.NET Framework Class Library |
Parallel..::.ForEach<(Of <(TSource>)>) Method (Partitioner<(Of <(TSource>)>), ParallelOptions, Action<(Of <(TSource, ParallelLoopState>)>)) |
Parallel Class See Also Send Feedback |
Executes a for each operation on a
Partitioner in which iterations may run in parallel.
Namespace:
System.Threading.Tasks
Assembly:
System.Threading (in System.Threading.dll)
Syntax
Visual Basic (Declaration) |
---|
Public Shared Function ForEach(Of TSource) ( _ source As Partitioner(Of TSource), _ parallelOptions As ParallelOptions, _ body As Action(Of TSource, ParallelLoopState) _ ) As ParallelLoopResult |
C# |
---|
public static ParallelLoopResult ForEach<TSource>( Partitioner<TSource> source, ParallelOptions parallelOptions, Action<TSource, ParallelLoopState> body ) |
Parameters
- source
- Type: System.Collections.Concurrent..::.Partitioner<(Of <(TSource>)>)
The Partitioner that contains the original data source.
- parallelOptions
- Type: System.Threading.Tasks..::.ParallelOptions
A ParallelOptions instance that configures the behavior of this operation.
- body
- Type: System..::.Action<(Of <(TSource, ParallelLoopState>)>)
The delegate that is invoked once per iteration.
Type Parameters
- TSource
- The type of the elements in source.
Return Value
A ParallelLoopResult structure that contains information on what portion of the loop completed.Remarks
The Partitioner is used to retrieve the elements to be processed, in place of the original data source. If the current element's index is desired, the source must be an OrderablePartitioner.
The body delegate is invoked once for each element in the source Partitioner. It is provided with the following parameters: the current element, and a ParallelLoopState instance that may be used to break out of the loop prematurely.
Exceptions
Exception | Condition |
---|---|
System..::.ArgumentNullException | The exception that is thrown when the source argument is null. |
System..::.ArgumentNullException | The exception that is thrown when the parallelOptions argument is null. |
System..::.ArgumentNullException | The exception that is thrown when the body argument is null. |
System..::.OperationCanceledException | The exception that is thrown when the CancellationToken in the parallelOptions argument is set |
System..::.InvalidOperationException | The exception that is thrown when the SupportsDynamicPartitions property in the source Partitioner returns false. |
System..::.InvalidOperationException | The exception that is thrown when any methods in the source Partitioner return null. |
System..::.InvalidOperationException | The exception that is thrown when the GetPartitions() method in the source Partitioner does not return the correct number of partitions. |
System..::.InvalidOperationException | The exception that is thrown when the GetPartitions() method in the source Partitioner returns an IList with at least one null value. |
System..::.InvalidOperationException | The exception that is thrown when the GetDynamicPartitions() method in the source Partitioner returns an IEnumerable whose GetEnumerator() method returns null. |
System..::.AggregateException | The exception that is thrown to contain an exception thrown from one of the specified delegates. |
System..::.ObjectDisposedException | The exception that is thrown when the the CancellationTokenSource associated with the the CancellationToken in the parallelOptions has been disposed. |